//package com.lsc.admin.demo.mq;
//
//import java.util.Optional;
//
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.kafka.support.Acknowledgment;
//import org.springframework.kafka.support.KafkaHeaders;
//import org.springframework.messaging.handler.annotation.Header;
//import org.springframework.stereotype.Component;
//
//import lombok.extern.slf4j.Slf4j;
//
//@Component
//@Slf4j
//@ConditionalOnProperty(prefix="spring.kafka",name = "enabled", havingValue = "true")
//public class KafkaConsumer {
//
//	/**
//	 * 使用group实现消息订阅模式，不同group都会接收到消息，相同group只有一个接收消息
//	 */
//    public static final String TOPIC_GROUP1 = "topic.group1";
//    public static final String TOPIC_GROUP2 = "topic.group2";
//    
//	
//    @KafkaListener(topics = "${spring.kafka.topic-name:''}", groupId = TOPIC_GROUP1)
//    public void topic_test(ConsumerRecord<?, ?> record, Acknowledgment ack, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) {
//        Optional message = Optional.ofNullable(record.value());
//        if (message.isPresent()) {
//            Object msg = message.get();
//            log.info("topic_test 消费了： Topic:" + topic + ",Message:" + msg);
//            ack.acknowledge();
//        }
//    }
//
//    @KafkaListener(topics = "${spring.kafka.topic-name:''}", groupId = TOPIC_GROUP2)
//    public void topic_test1(ConsumerRecord<?, ?> record, Acknowledgment ack, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) {
//
//        Optional message = Optional.ofNullable(record.value());
//        if (message.isPresent()) {
//            Object msg = message.get();
//            log.info("topic_test1 消费了： Topic:" + topic + ",Message:" + msg);
//            ack.acknowledge();
//        }
//    }
//}